<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    <meta name="format-detection" content="address=no" />
    <meta name="format-detection" content="date=no" />
    <title>设置</title>
    <link href="../../css/api.css" rel="stylesheet" type="text/css">
    <link href="../../css/aui.css" rel="stylesheet" type="text/css">
    <link href="../../css/index.css" rel="stylesheet" type="text/css">
    <link href="../../css/public_win.css" rel="stylesheet" type="text/css">
    <link href="../../css/public.css" rel="stylesheet" type="text/css">
    <style>
        /*html,
        body {
            height: 100%;
            background: rgba(0, 0, 0, 0)
        }*/
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>

        <div class="space"></div>
        <div class="public_list">
            <div class="public_item" tapmode @click="custId!=''?fnOpenPublicWin('修改手机号', 'mine/mobile_phone',{'phone':phone}):fnOpenLogin()">
                <span class="public_item_left">账号管理</span>
                <img class="public_item_right_img" src="../../image/mine/go_page.png" alt="">
            </div>
            <div class="public_item" tapmode @click="custId!=''?fnOpenPublicWin('密码管理', 'mine/password_management',{'phone':phone}):fnOpenLogin()">
                <span class="public_item_left">密码管理</span>
                <img class="public_item_right_img" src="../../image/mine/go_page.png" alt="">
            </div>
            <div class="public_item" tapmode @click="custId!=''?fnOpenPublicWin('安全锁设置', 'mine/safety_lock_setting'):fnOpenLogin()">
                <span class="public_item_left">安全锁设置</span>
                <img class="public_item_right_img" src="../../image/mine/go_page.png" alt="">
            </div>
        </div>
        <div class="space"></div>
        <div class="public_list">
            <div class="public_item" tapmode @click="fnSetTags()">
                <span class="public_item_left">消息推送</span>
                <div type="checkbox" :class="pushId=='1'?'aui-switch':'aui-switch aui_active'"></div>
                <!-- <img class="public_item_right_img" src="../../image/mine/go_page.png" alt=""> -->
            </div>
            <div class="public_item" tapmode @click="custId!=''?fnOpenPublicWin('第三方账号', 'mine/third_bind'):fnOpenLogin()">
                <span class="public_item_left">第三方绑定</span>
                <img class="public_item_right_img" src="../../image/mine/go_page.png" alt="">
            </div>
            <div class="public_item" tapmode onclick="fnClearCache()">
                <span class="public_item_left">清理缓存</span>
                <span class="public_item_content">{{cache}}</span>
                <img class="public_item_right_img" src="../../image/mine/go_page.png" alt="">
            </div>
        </div>
        <div class="space"></div>
        <div class="public_list">
            <div class="public_item" tapmode @click="custId!=''?fnOpenComplaintList():fnOpenLogin()">
                <span class="public_item_left">投诉与建议</span>
                <!-- <span class="public_item_content red"></span> -->
                <img class="public_item_right_img" src="../../image/mine/go_page.png" alt="">
            </div>
            <div class="public_item" tapmode onclick="fnOpenPublicWin('关于心际空间', 'mine/about_us')">
                <span class="public_item_left">关于心际空间</span>
                <img class="public_item_right_img" src="../../image/mine/go_page.png" alt="">
            </div>
        </div>
        <div class="bottom_btn_div">
            <div class="bottom_btn logout_btn" v-if="custId!=''" tapmode onclick="fnLogout()">退出登录</div>
        </div>
    </div>
</body>

<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-font.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-login.js"></script>
<script type="text/javascript" src="../../script/service/service-verify.js"></script>
<script type="text/javascript">
    var $S, USER;
    var vm;
    apiready = function() {
        $S = SERVICE();
        USER = USER();
        fnInit();
        setTimeout(function() {
            fnSetPlayFrmFront();
        }, 300);

        fnCache();
        vm.pushId = api.getPrefs({
            sync: true,
            key: 'pushTag'
        })


    }

    function fnInit() {
        vm = new Vue({
            el: ".vueApp",
            data: {
                phone: api.pageParam.phone || "",
                custId: USER.Get("custId", true) || "",
                cache: "",
                pushId: "",
            },
            methods: {

            }
        })
    }

    function fnSetPhone(phone) {
        if (phone && phone != "") {
            vm.phone = phone;
        }
    }
    // 退出登录
    function fnLogout() {
        var param = {
            alertConfirmFn: "logount()",
            alertType: "3"
        }
        fnOpenAlert(param);
    }

    function logount() {
        USER.Clear();
        vm.custId = USER.Get("custId", true) || "";
        api.sendEvent({
            name: 'loginStatus',
            extra: {
                login: false,
            }
        });
        var param = {
            name: 'login',
            url: '../login/login.html',
        }
        fnOpenWin(param)
    }

    function fnOpenComplaintList() {
        var param = {
            name: "complaint_win",
            url: "../mine/complaint_win.html",
        }
        fnOpenWin(param)
    }
    //清除缓存
    function fnClearCache() {
        if (vm.cache != "0B") {
            api.confirm({
                title: '提示',
                msg: '是否清除缓存？',
                buttons: ['确定', '取消']
            }, function(ret, err) {
                var index = ret.buttonIndex;
                if (index == "1") {
                    api.clearCache(function() {
                        api.toast({
                            msg: '清除成功'
                        });
                        vm.cache = "0B";
                    });
                }
            });
        } else {
            api.toast({
                msg: '暂无缓存',
                duration: 2000,
                location: 'bottom'
            });

        }
    }
    //获取缓存的大小
    function fnCache() {
        api.getCacheSize(function(ret) {
            var size = ret.size;
            if (size > 0) {
                vm.cache = bytesToSize(size);
            } else {
                vm.cache = "0B";
            }
        });
    }
    //计算缓存大小
    function bytesToSize(bytes) {
        if (bytes === 0) return '0B';
        var k = 1024;
        sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
        i = Math.floor(Math.log(bytes) / Math.log(k));
        return Math.floor((bytes / Math.pow(k, i))) + ' ' + sizes[i];
    }

    function fnOpenLogin() {
        var param = {
            name: 'login',
            url: '../login/login.html',
        }
        fnOpenWin(param)
    }

    function fnSetTags() {
        if (vm.pushId == '1') {
            if (fnCheckIsOpenLogin()) {
                vm.pushId = USER.Get("custId", true)
            } else {
                vm.pushId = "";
            }
        } else {
            vm.pushId = '1';
        }
        api.setPrefs({
            key: 'pushTag',
            value: vm.pushId
        });
        setTimeout(function() {
            api.execScript({
                name: 'main',
                script: 'fnBindTag();'
            });
        }, 300)
    }
</script>

</html>
